<?
define('BASEPATH', true);
include('../inc/config.php');
if(!$is_online){exit;}

if(isset($_POST['data'])){
	$id = $db->EscapeString($_POST['data']);
	$site =  $db->FetchArray($db->Query("SELECT id,cpc FROM `youtube` WHERE `youtube`='".$id."'"));
	$check = $db->GetNumRows($db->Query("SELECT id FROM `viewed` WHERE `user_id`='".$data['id']."' AND `site_id`='".$site['id']."'"));
	if($site['id'] != "" && $check == 0){
		$db->Query("UPDATE `users` SET `coins`=`coins`+'".$site['cpc']."' WHERE `id`='".$data['id']."'");
		$db->Query("UPDATE `youtube` SET `views`=`views`+'1', `points`=`points`-'".$site['cpc']."' WHERE `id`='".$site['id']."'");
		$db->Query("INSERT INTO `viewed` (user_id, site_id) VALUES('".$data['id']."','".$site['id']."')");
	}
}
?>